﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace _201206QuanLyBanHang.ChucNang
{
    class BLL_ChietKhau
    {
        DataConn da;
        public BLL_ChietKhau()
        {
            da = new DataConn();
        }
        public DataSet getDMkhachhang(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
        public DataSet getDMSanpham(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
        public DataSet getDMChietKhau(string strsql)
        {
            return da.ExectueQueryDataset(strsql, CommandType.Text, null);
        }
        public bool insertDMChietKhau(ref string err, int makh, string masp, double giachietkhau,DateTime ngaychietkhau,string ghichu)
        {
            return da.MyExecuteNonQuery("Pro_Insert_DMChietKhau", CommandType.StoredProcedure, ref err, new SqlParameter("@makh", makh), new SqlParameter("@masp", masp), new SqlParameter("@giachietkhau", giachietkhau), new SqlParameter("@ngaychietkhau", ngaychietkhau), new SqlParameter("@ghichu",ghichu));
        }
        public bool deleteDMChietKhau(ref string err, int makh,string masp)
        {
            return da.MyExecuteNonQuery("Pro_Delete_DMChietKhau", CommandType.StoredProcedure, ref err, new SqlParameter("@makh", makh), new SqlParameter("@masp", masp));
        }
        public bool updateDMChietKhau(ref string err, int makh, string masp, double giachietkhau, DateTime ngaychietkhau,string ghichu)
        {
            return da.MyExecuteNonQuery("Pro_Update_DMChietKhau", CommandType.StoredProcedure, ref err, new SqlParameter("@makh", makh), new SqlParameter("@masp", masp), new SqlParameter("@giachietkhau", giachietkhau), new SqlParameter("@ngaychietkhau", ngaychietkhau), new SqlParameter("@ghichu",ghichu));
        }
        public void fillCombo(string sql, ComboBox cmb, string text, string value)
        {
            DataSet ds = new DataSet();
            ds = da.ExectueQueryDataset(sql, CommandType.Text, null);

            cmb.DataSource = ds.Tables[0];
            cmb.DisplayMember = text;
            cmb.ValueMember = value;
            cmb.SelectedIndex = -1;
        }
        public double LayGiaSanPham(String MaSP)
        {

            String sql = "select GiaSP from SanPham where MaSP=" + MaSP;
            return da.TraveDongDuLieu(sql);
        }
        public object layma(ref string err, string str)
        {

            return da.lay(str, CommandType.Text, ref err);


        }
        public bool insertDMLogChietKhau(ref string err, int stt, string masp,double giasp,int makh,int manhanvien, double giachietkhau, DateTime ngaychietkhau)
        {
            return da.MyExecuteNonQuery("Pro_Insert_DMlogchieukhau", CommandType.StoredProcedure, ref err, new SqlParameter("@stt", stt), new SqlParameter("@masp", masp), new SqlParameter("@giasp", giasp), new SqlParameter("@makh", makh), new SqlParameter("@manhanvien", manhanvien), new SqlParameter("@giachietkhau", giachietkhau), new SqlParameter("@ngaychietkhau", ngaychietkhau));
        }
        public DataTable LayThongtinTimkiem(String makhuvuc, String tenkhachhang)
        {
            String sql = "select makh,tencuahang from khachhang a, khuvuc b where a.makhuvuc=b.makhuvuc and a.makhuvuc='" + makhuvuc + "' and Tencuahang like '%" + tenkhachhang + "%'";

            return da.GetDataTable(sql);
        }
    }
}
